<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html xmlns:th="" lang="zh-CN">
<%@include file="/WEB-INF/pages/base/include_article.jsp"%>
<body>
<div id="wrapper">
    <%@include file="/WEB-INF/pages/base/menu.jsp"%>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">商品管理</h3>
            </div>
        </div>
        <div class="row">
            <form class="form-horizontal" data-parsley-validate>
                <div class="col-lg-12 col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">商品基本信息</div>
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-12 col-md-12">
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品名称：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="name" class="form-control" placeholder="请输入商品名称"
                                                   required>
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品销售价：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="salesPrice" class="form-control"
                                                   placeholder="请输入商品销售价">
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品市场价：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="marketPrice" class="form-control"
                                                   placeholder="请输入商品市场价">
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品库存：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="stock" class="form-control"
                                                   placeholder="请输入商品库存">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品限购数量：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="stockAlgorithm" class="form-control"
                                                   placeholder="请输入商品限购数量">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品首页推荐排列顺序<br>(数字越小越靠前)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="orderNumber" class="form-control"
                                                   placeholder="请输入商品首页排列顺序">
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">——可填——</span>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">开始时间：</label>
                                        <div class="col-lg-8">
                                            <input class="form-control" id="startTime" type="text" placeholder="开始时间">
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须选择</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">结束时间：</label>
                                        <div class="col-lg-8">
                                            <input class="form-control" id="endingTime" type="text" placeholder="结束时间">
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须选择</span>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商盟惠购说订阅号文章链接：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="nuoaUrl" class="form-control"
                                                   placeholder="请输入链接地址">
                                        </div>
                                    </div>
                                    <!-- <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品评级编号：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="certificateNumber" class="form-control"
                                                   placeholder="请输入商品评级编号">
                                        </div>
                                    </div> -->
                                    <div class="form-group">
                                         <label class="col-lg-2 clo-md-2 control-label">商品规格图<br>(800 X 800)：</label>
                                         <div class="col-lg-8">
                                             <p><img id="formatImage" src="" width="50px"></p>
                                             <button class="btn btn-default" id="photoUpload_3">上传图片</button>
                                         </div>
                                     </div>
                                     <div class="form-group no-filereader-hidden">
                                        <label class="col-sm-2 control-label"></label>
                                        <div class="col-sm-10">
                                            <div class="tag-wrapper" id="attachmentTag_3"></div>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">品牌名称：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="brandName" class="form-control"
                                                   placeholder="请输入品牌名称">
                                        </div>

                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">净含量：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="netVolume" class="form-control"
                                                   placeholder="请输入净含量">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">产地：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="placeOfOrigin" class="form-control"
                                                   placeholder="请输入产地">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">生产日期：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="manufacturerDate" class="form-control"
                                                   placeholder="请输入生产日期">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">成分：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="storageMethod" class="form-control"
                                                   placeholder="请输入成分">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">保质期：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="durabilityPeriod" class="form-control"
                                                   placeholder="请输入保质期">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">适用人群：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="peopleFor" class="form-control"
                                                   placeholder="请输入适用人群">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">使用方法：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="useMethod" class="form-control"
                                                   placeholder="请输入使用方法">
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">——可填——</span>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品供应商：</label>
                                        <div class="col-lg-8" id="productSellerList">
                                        	<select class="form-control" id="productSeller">
                                        	<c:forEach var="item" items="${productSellerList}" varStatus="status">
						                             <option value="${item.productSellerId}">${item.productSellerName}</option>
						                    </c:forEach>
						                    </select>
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品销售范围：</label>
                                        <div class="col-lg-8" id="mallList">
                                        	<c:forEach var="item" items="${mallList}" varStatus="status">
						                             <input type="checkbox" name="saleArea" value="${item.mallUuid}">${item.mallName}
						                    </c:forEach>
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                   <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品首页展示类型：</label>
                                    	<div class="col-lg-8">
	                                        <select class="form-control" id="productType">
		                                            <option value="0">单排</option>
		                                            <option value="1">双排</option>
	                                        </select>
                                    	</div>
                                    	<div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品一级类别：</label>
                                    	<div class="col-lg-8">
	                                        <select class="form-control" id="productCategory">
		                                            <c:forEach var="item" items="${categoryList}" varStatus="status">
		                                            	<option value="${item.id}">${item.name}</option>
					                   			 	</c:forEach>
	                                        </select>
                                    	</div>
                                    	<div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">积分返利比例(%)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="backPercent" class="form-control"
                                                   placeholder="请输入积分返利比例">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">首次购买给合伙人奖励比例(%)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="partnerReward" class="form-control"
                                                   placeholder="请输入首次购买给合伙人奖励比例">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">第二次购买给合伙人奖励比例(%)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="partnerReward2" class="form-control"
                                                   placeholder="请输入第二次购买给合伙人奖励比例">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">首次购买给店主奖励比例(%)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="shopReward" class="form-control"
                                                   placeholder="请输入首次购买给店主奖励比例">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">第二次购买给店主奖励比例(%)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="shopReward2" class="form-control"
                                                   placeholder="请输入第二次购买给店主奖励比例">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">首次购买给会员奖励比例(%)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="nomalReward" class="form-control"
                                                   placeholder="请输入首次购买给会员奖励比例">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">第二次购买给会员奖励比例(二级)(%)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="nomalReward2" class="form-control"
                                                   placeholder="请输入第二次购买给会员奖励比例">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品打折满足金额(元)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="uplevelPrice" class="form-control"
                                                   placeholder="请输入打折满足金额">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品打折折扣(%)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="uplevelPercent" class="form-control"
                                                   placeholder="请输入打折折扣">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商城首页简述：</label>
                                        <div class="col-lg-8">
                                            <textarea class="form-control" rows="3" id="shortName"
                                                      placeholder="请输入商品简述"></textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品详情页描述：</label>
                                        <div class="col-lg-8">
                                            <textarea class="form-control" rows="3" id="desc"
                                                      placeholder="请输入商品描述"></textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品备注：</label>
                                        <div class="col-lg-8">
                                            <textarea class="form-control" rows="3" id="remark"
                                                      placeholder="请输入商品备注"></textarea>
                                        </div>
                                    </div>
                                    <hr>
                                    <div class="form-group">
                                         <label class="col-lg-2 clo-md-2 control-label">商品海报图<br>(750 X 450)：</label>
                                         <div class="col-lg-8">
                                             <p><img id="image5" src="" width="200px"></p>
                                             <button class="btn btn-default" id="photoUpload_4">上传图片</button>
                                         </div>
                                     </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-12 control-label">商品照片<br>(750 X 450)：</label>
                                        <div class="col-lg-10 col-md-12 ">
                                            <button class="btn btn-default" id="photoUpload_1">上传图片</button>
                                            <div class="clearfix"></div>
                                            <span class="help-block" style="display: inline-block;">(1~4张图片)</span>
                                            <input type="hidden" name="attachmentUuid_1"/>
                                            <input type="hidden" name="attachmentUrl_1"
                                                   value=""/>
                                        </div>
                                    </div>
                                    <div class="form-group no-filereader-hidden">
                                        <label class="col-sm-2 control-label"></label>
                                        <div class="col-sm-10">
                                            <div class="tag-wrapper" id="attachmentTag_1"></div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-1 clo-md-1 control-label">详情：</label>
                                        <div class="col-lg-8">
                                            <script id="editor" name="upfile" type="text/plain" style="width:1024px;height:500px;"/>
                                        </div>
                                        <div class="col-lg-1 clo-md-1">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                    <!-- <div class="form-group">
                                        <label class="col-lg-2 clo-md-12 control-label">商品详情图<br>(800 X 800)：</label>
                                        <div class="col-lg-10 col-md-12 ">
                                            <button class="btn btn-default" id="photoUpload_2">上传图片</button>
                                            <div class="clearfix"></div>
                                            <span class="help-block" style="display: inline-block;">(任意数量张图片)</span>
                                            <input type="hidden" name="attachmentUuid_2"/>
                                            <input type="hidden" name="attachmentUrl_2"
                                                   value=""/>
                                        </div>
                                    </div>
                                    <div class="form-group no-filereader-hidden">
                                        <label class="col-sm-2 control-label"></label>
                                        <div class="col-sm-10">
                                            <div class="tag-wrapper" id="attachmentTag_2"></div>
                                        </div>
                                    </div> -->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
                <button type="button" class="btn btn-primary" onclick="product_create()"
                        style="margin-left:15px;margin-bottom:30px;">发布
                </button>
                <button class="btn btn-default" id="cancel" style="margin-left:15px;margin-bottom:30px;">
                  		  取消
                </button>
            </form>
        </div>
    </div>
</div>
<script>
	//实例化编辑器
	//建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
	var ue = UE.getEditor('editor');
	UE.Editor.prototype._bkGetActionUrl=UE.Editor.prototype.getActionUrl;
	UE.Editor.prototype.getActionUrl=function(action){
	    if (action == 'uploadimage' ||action== 'uploadscrawl' || action == 'uploadimage') {
	    	//return this._bkGetActionUrl.call(this, action);
	    	//return '${path}/tools/imageController/upload';
	    	return '${webPath}/file/upload';
	    }else if(action =='uploadvideo') {
	    	return '${webPath}/file/upload';
	    }else if(action == 'listimage'){
	    	return this._bkGetActionUrl.call(this, action);
	    }else{
	    	return this._bkGetActionUrl.call(this, action);
	    }
	}

	var images = [];
	var currentI = 0;

	$(function(){
		var type = "${type}";
		if(type == "3"){
			$("#orderNumber_div").hide();
		}
	});

	function product_create() {

		var haveContent = UE.getEditor('editor').hasContents();
		if(haveContent){
    		var content = UE.getEditor('editor').getContent();

    		var baseURL = "${webPath}/product/create";
            var name = $('#name').val();
            var salesPrice = $('#salesPrice').val();
            var marketPrice = $('#marketPrice').val();
            var stock = $('#stock').val();
            var stockAlgorithm = $('#stockAlgorithm').val();
            var shortName=$('#shortName').val();

            var orderNumber = $('#orderNumber').val();
            var nuoaUrl = $('#nuoaUrl').val();
            var formatImage = $("#formatImage")[0].src;
            var image5 = $("#image5")[0].src;
            var startTime = $('#startTime').val();
            var endingTime = $('#endingTime').val();

    		var sellingPoint="暂时屏蔽";
    		var desc = $('#desc').val();
    		var remark = $('#remark').val();
    		var attachmentUrl_1 = $('input[name="attachmentUrl_1"]').val();
    		var productType = $("#productType").find("option:selected").val();

    		var brandName=$('#brandName').val();
    		var netVolume=$('#netVolume').val();
    		var placeOfOrigin=$('#placeOfOrigin').val();
    		var manufacturerDate=$('#manufacturerDate').val();
    		var storageMethod=$('#storageMethod').val();
    		var durabilityPeriod=$('#durabilityPeriod').val();
    		var peopleFor=$('#peopleFor').val();
    		var useMethod=$('#useMethod').val();

    		var type = "${type}";
    		if(type != "1" && productType == 1){
    			alert("当前账号无权限操作套餐商品");
    			return;
    		}

    		var productSeller = $("#productSeller").find("option:selected").val();
    		var productCategory = $("#productCategory").find("option:selected").val();

    		var saleAreaList = [];
    		$('input[name="saleArea"]:checked').each(function() {
    			saleAreaList.push($(this).val());
    		});

    		var partnerReward = $('#partnerReward').val();
    		var partnerReward2 = $('#partnerReward2').val();
    		var shopReward = $('#shopReward').val();
    		var shopReward2 = $('#shopReward2').val();
    		var nomalReward = $('#nomalReward').val();
    		var nomalReward2 = $('#nomalReward2').val();
    		var backPercent = $('#backPercent').val();
    		var uplevelPrice = $('#uplevelPrice').val();
    		var uplevelPercent = $('#uplevelPercent').val();

    		var json_package = {
    			"head" : {},
    			"body" : {
    				"name" : name,
    				"salesPrice" : salesPrice,
    				"marketPrice" : marketPrice,
    				"stock" : stock,
    				"stockAlgorithm" : stockAlgorithm,
    				"productType" : productType,
    				"productSeller" : productSeller,
    				"productCategory" : productCategory,
    				"saleAreaList" : saleAreaList,
    				"desc" : desc,
    				"remark" : remark,
    				"imageList" : attachmentUrl_1,
    				"content" : content,
    				"shortName" : shortName,
    				"sellingPoint" : sellingPoint,
    				"orderNumber":orderNumber,
    				"nuoaUrl":nuoaUrl,
    				"formatImage":formatImage,
    				"image5":image5,
    				"startTime": startTime,
                    "endingTime": endingTime,
                    "partnerReward": partnerReward,
                    "partnerReward2": partnerReward2,
                    "shopReward": shopReward,
                    "shopReward2": shopReward2,
                    "nomalReward": nomalReward,
                    "nomalReward2": nomalReward2,
                    "backPercent": backPercent,
                    "uplevelPrice": uplevelPrice,
                    "uplevelPercent": uplevelPercent,
                    "brandName": brandName,
                    "netVolume": netVolume,
                    "placeOfOrigin": placeOfOrigin,
                    "manufacturerDate": manufacturerDate,
                    "storageMethod": storageMethod,
                    "durabilityPeriod": durabilityPeriod,
                    "peopleFor": peopleFor,
                    "useMethod": useMethod
    			}
    		};
    		$.post(baseURL, {
    			"json_package" : JSON.stringify(json_package)
    		}, function(result) {
    			if (typeof result == 'string')
    				result = JSON.parse(result);
    			if (result.body.result == '0') {
    				alert(result.body.description)
    				window.location.href = "${webPath}toProductEdit/"
    						+ result.body.productId;
    			} else {
    				alert(result.body.description)
    			}
    		})
		}
	}

	function closeDiv(i) {
		$("#rewardDiv" + i).remove();
		currentI--;
	}

	function addNewReward() {
		var accountRewardListString = '';
		accountRewardListString += '<div style="border:1px solid gray;padding:10px;border-radius:5px;margin-top:5px;" id="rewardDiv'
				+ (currentI + 1) + '">';
		accountRewardListString += '	<a style="float:right;text-decoration:none;cursor:default" onclick=closeDiv("'
				+ (currentI + 1) + '") >X</a>';
		accountRewardListString += '(一级(单位：%))<input type="text" name="rewardList" class="form-control" value="" placeholder="请输入商品用户一级佣金比例" >';
		accountRewardListString += '(二级(单位：%))<input type="text" name="rewardList2" class="form-control" value="" placeholder="请输入商品用户二级佣金比例" >';
		accountRewardListString += '(单位：天)<input type="text" name="rewardTime" class="form-control" value="" placeholder="请输入商品用户佣金时间" >';
		accountRewardListString += '</div>';
		$("#accountRewardList").append(accountRewardListString);
		currentI++;
	}
	$(function() {
		$('#cancel').click(function() {
			window.location.href = "${webPath}toProduct";
		})
	});
	(function() {
		var attachementList = [], attachementUrl = [];
		var updateUpload = function() {
			$('input[name="attachmentUuid_1"]').val(JSON.stringify({
				attachment : attachementList
			}));
			$('input[name="attachmentUrl_1"]').val(attachementUrl);
			$('input[name="attachmentUrl_1"]').val(images);
		};
		var updateImage = function() {
			if (attachementUrl.length == 0) {
				return

			} else {
				attachementUrl
						.forEach(function(attachment, index) {
							$('#attachmentTag_1')
									.append(
											'<div class="col-lg-3 col-md-4" style="padding-left:0px;"><div class="tag-box attachment-tag uploadifive-queue-item"><span class="icon-attachment"></span><span class="filename"></span><span class="fileinfo"></span><span type="button" aria-hidden="close" class="close"><span aria-hidden="true" style="color:#fff;">&times;</span></span><div class="tag-box-lower"><a href="+attachment+" data-lightbox="example-set"><img src='
													+ attachment
													+ ' style="width:100%; height:auto;"/ alt="" /></a></div></div></div>')
						})
			}
			$('input[name="attachmentUrl_1"]').val(attachementUrl);
		};
		updateImage();
		var ajaxUpload = new AjaxUpload(
				$('#photoUpload_1'),
				{
					action : '${webPath}/file/uploadImage',
					data : {
						"json_package" : JSON.stringify({
							"head" : {},
							"body" : {
								"file" : "file"
							}
						})
					},
					name : 'file',
					onSubmit : function(file, ext) {
						window.uploading = true;
						$('#photoUpload_1').text('上传中...');
						$('#photoUpload_1').attr('disabled', true);
						this.disable();

					},
					onChange : function(file, extension) {
						this.disable();
					},
					onComplete : function(file, response) {
						var data = JSON.parse(response);
						var result = data.body.result;
						var description = data.body.description;
						if(result == "1"){
							alert("图片太大");
							window.uploading = false;
							this.enable();
							return;
						}

						var fileUrl = data.body.fileUrl;
						attachementUrl.push(fileUrl);
						attachementList.push(fileUrl);
						images.push(fileUrl);
						updateUpload();
						var fileName = file.length > 25 ? file.substring(0, 24)
								+ "..." : file;
						$('#attachmentTag_1')
								.append(
										'<div class="col-lg-3 col-md-4" style="padding-left:0px;"><div class="tag-box attachment-tag uploadifive-queue-item"><span class="icon-attachment"></span><span class="filename">'
												+ fileName
												+ ' </span><span class="fileinfo"></span><span type="button" aria-hidden="close" class="close"><span aria-hidden="true" style="color:#fff;">&times;</span></span><div class="tag-box-lower"><a href=' + fileUrl + ' data-lightbox="example-set"><img src='
												+ fileUrl
												+ ' style="width:100%; height:auto;"/></a></div></div></div>');
						window.uploading = false;
						$('#photoUpload_1').text('上传图片');
						this.enable();
					}
				});
		//setTimeout("ajaxUpload()", 2000);

		$("#attachmentTag_1").on(
				'click',
				".attachment-tag .close",
				function(e) {
					e.stopPropagation();
					var targetTag = $(this).parents('.attachment-tag');
					var order = $("#attachmentTag_1 .attachment-tag").index(
							targetTag);
					if (order > -1) {
						attachementList.splice(order, 1);
						attachementUrl.splice(order, 1);
						images.splice(order, 1);
						updateUpload();
						$(this).parents('.col-lg-3').remove();
					}
					return false
				});
	})();

	(function(){
		var ajaxUpload = new AjaxUpload($('#photoUpload_3'), {
		    action: '${webPath}/file/uploadImage',
		    data: {
		        "json_package": JSON.stringify({
		            "head": {},
		            "body": {"file": "file"}
		        })
		    },
		    name: 'file',
		    onSubmit: function (file, ext) {
		        window.uploading = true;
		        $('#photoUpload_3').text('上传中...');
		        $('#photoUpload_3').attr('disabled', true);
		        this.disable();

		    },
		    onChange: function (file, extension) {
		        this.disable();
		    },
		    onComplete: function (file, response) {
		    	var data = JSON.parse(response);

		    	var result = data.body.result;
				var description = data.body.description;
				if(result == "1"){
					alert("图片太大");
					window.uploading = false;
					this.enable();
					return;
				}

				var fileUrl = data.body.fileUrl;

		    	$("#formatImage").attr('src',fileUrl);
		        window.uploading = false;
		        $('#photoUpload_3').text('上传图片');
		        this.enable();
		    }
		});
	})();
	(function(){
		var ajaxUpload = new AjaxUpload($('#photoUpload_4'), {
		    action: '${webPath}/file/uploadImage',
		    data: {
		        "json_package": JSON.stringify({
		            "head": {},
		            "body": {"file": "file"}
		        })
		    },
		    name: 'file',
		    onSubmit: function (file, ext) {
		        window.uploading = true;
		        $('#photoUpload_4').text('上传中...');
		        $('#photoUpload_4').attr('disabled', true);
		        this.disable();

		    },
		    onChange: function (file, extension) {
		        this.disable();
		    },
		    onComplete: function (file, response) {
		    	var data = JSON.parse(response);

		    	var result = data.body.result;
				var description = data.body.description;
				if(result == "1"){
					alert("图片太大");
					window.uploading = false;
					this.enable();
					return;
				}

				var fileUrl = data.body.fileUrl;

		    	$("#image5").attr('src',fileUrl);
		        window.uploading = false;
		        $('#photoUpload_4').text('上传图片');
		        this.enable();
		    }
		});
	})();

	$(function () {
        $('#startTime').datetimepicker({
            format: 'YYYY-MM-DD HH:mm:ss'
        });
        $('#endingTime').datetimepicker({
            format: 'YYYY-MM-DD HH:mm:ss'
        });
        $('#startTime').datetimepicker();
        $('#endingTime').datetimepicker({
            useCurrent: false //Important! See issue #1075
        });
        $("#startTime").on("dp.change", function (e) {
            $('#endingTime').data("DateTimePicker").minDate(e.date);
        });
        $("#endingTime").on("dp.change", function (e) {
            $('#startTime').data("DateTimePicker").maxDate(e.date);
        });
    });

	$(document).ready(function(e) {
		$('#pro_info').keydown(function() {
			var len = $(this).val().length;
			if (len >= 100) {
				var num = $(this).val().substring(0, 99);
				$(this).val(num);
				alert("超过字数限制")
			}
		})
	});
	$(document).ready(function(e) {
		$('#pro_desc').keydown(function() {
			var len = $(this).val().length;
			if (len >= 140) {
				var num = $(this).val().substring(0, 139);
				$(this).val(num);
				alert("超过字数限制")
			}
		})
	});
</script>
</body>
</html>